package com.omronservice.app.curve.service;


import com.omronservice.app.curve.bean.copycurve.CopyCurve2Bean;
import com.omronservice.app.curve.bean.copycurve.CopyCurveBean;
import com.omronservice.app.curve.bean.maincurve.SelectAllDataBean;
import com.omronservice.app.curve.bean.maincurve.SelectAllDataResBean;
import com.omronservice.app.curve.bean.maincurve.SelectCapacityBean;
import com.omronservice.app.curve.bean.maincurve.SelectEquBean;
import com.omronservice.app.curve.mapper.CopyCurveMapper;
import com.omronservice.app.curve.mapper.CurveMapper;
import com.omronservice.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Service
public class CopyCurveService {

    private final static String A = "0";

    private final static String B = "1";


    @Autowired
    CopyCurveMapper copyCurveMapper;


    public CopyCurveBean selectWidth(String startDate, String endDate,
                                     String startDate2, String endDate2,String type
                                     ,String eqNo,String lindId,String abFlg,String selectType) {
        CopyCurveBean bean=new CopyCurveBean();
        List<HashMap<String,String>> listA=new ArrayList<>();
        List<HashMap<String,String>> listB=new ArrayList<>();
        double sumA = 0;
        double sumB=0;
        double countA=0;
        double countB=0;
        if("1".equals(selectType)) {//按片
        switch (type){
            case "1":
                    if ("1".equals(abFlg)) {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthAB(startDate, endDate, startDate2, endDate2, lindId);
                        //List<HashMap<String, Object>> abAvg = copyCurveMapper.selectWidthAvg(startDate, endDate, startDate, endDate, lindId);

                        for (HashMap<String, String> map : listAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA += Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB += Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if (countA > 0) bean.setaAvg(Double.toString(sumA / countA));
                        if (countB > 0) bean.setbAvg(Double.toString(sumB / countB));
                        //for (HashMap<String, Object> map : abAvg) {
                        //if (A.equals(map.get("type"))) {
                        //bean.setaAvg(map.get("avg").toString());
                        //} else {
                        //bean.setbAvg(map.get("avg").toString());
                        //}
                        //}
                        bean.setaList(listA);
                        bean.setbList(listB);
                    } else {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthNoAB(startDate, endDate, lindId);
                        //List<HashMap<String, Object>> abAvg = copyCurveMapper.selectWidthNoAvg(startDate, endDate, lindId);
                        for (HashMap<String, String> map : listAB) {
                            //if (A.equals(map.get("type")))
                            //{
                            listA.add(map);
                            //}
                            //else {
                            //listB.add(map);
                            //}
                        }
                        if (listAB.size() > 0) {
                            bean.setaAvg(Double.toString(sumA / listAB.size()));
                            //bean.setaAvg(Double.toString(sumB/hamlListAB.size()));
                        }
                        //for (HashMap<String, Object> map : abAvg) {
                        //if (A.equals(map.get("type"))) {
                        //bean.setaAvg(map.get("avg").toString());
                        //} else {
                        //bean.setbAvg(map.get("avg").toString());
                        //}
                        //}
                        bean.setaList(listA);
                        //bean.setbList(listB);
                    }

                break;
            case "2":
                String weighNo1 ="";
                String weighNo2 ="";
                switch (eqNo){
                    case "1":
                        weighNo1 = "1";
                        weighNo2 = "2";
                        break;
                    case "2":
                        weighNo1 = "3";
                        weighNo2 = "4";
                        break;
                    case "3":
                        weighNo1 = "5";
                        weighNo2 = "6";
                        break;
                    case "4":
                        weighNo1 = "7";
                        weighNo2 = "8";
                        break;
                    default:
                        weighNo1 = "1";
                        weighNo2 = "2";
                        break;
                }
                if("1".equals(abFlg)) {
                    List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightAB(startDate, endDate, startDate2, endDate2, weighNo1, weighNo2, lindId);
                    List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightAvg(startDate, endDate, startDate, endDate, weighNo1, weighNo2, lindId);

                    for (HashMap<String, String> map : weightListAB) {
                        if (A.equals(map.get("type"))) {
                            listA.add(map);
                        } else {
                            listB.add(map);
                        }
                    }

                    for (HashMap<String, Object> map : weightAbAvg) {

                        if (A.equals(map.get("type"))) {
                            bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                        } else {
                            bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                        }
                    }
                    bean.setaList(listA);
                    bean.setbList(listB);
                }else {
                    List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightNOAB(startDate, endDate, weighNo1, weighNo2, lindId);
                    List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightNOAvg(startDate, endDate, weighNo1, weighNo2, lindId);

                    for (HashMap<String, String> map : weightListAB) {
                        if (A.equals(map.get("type"))) {
                            listA.add(map);
                        } else {
                            listB.add(map);
                        }
                    }

                    for (HashMap<String, Object> map : weightAbAvg) {

                        if (A.equals(map.get("type"))) {
                            bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                        } else {
                            bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                        }
                    }
                    bean.setaList(listA);
                    bean.setbList(listB);
                }
                break;
            case "3":
                if("1".equals(abFlg)) {
                    List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlAB(startDate, endDate, startDate2, endDate2, "1", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg = copyCurveMapper.selectHamlAvg(startDate, endDate, startDate, endDate, "1", lindId);

                    for (HashMap<String, String> map : hamlListAB) {
                        if (A.equals(map.get("type"))) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                            countA++;
                        } else {
                            listB.add(map);
                            sumB+=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }
                    }
                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    //for (HashMap<String, Object> map : hamlAbAvg) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    bean.setaList(listA);
                    bean.setbList(listB);
                }else {
                    List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlNoAB(startDate, endDate, "1", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg = copyCurveMapper.selectHamlNoAvg(startDate, endDate, "1", lindId);

                    for (HashMap<String, String> map : hamlListAB) {
                        //if (A.equals(map.get("type"))) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                        //}
                        //else {
                            //listB.add(map);
                            //sumB+=sumB+Double.parseDouble(map.get("yValue"));
                        //}
                    }

                    if(hamlListAB.size()>0)
                    {
                        bean.setaAvg(Double.toString(sumA/hamlListAB.size()));
                        //bean.setaAvg(Double.toString(sumB/hamlListAB.size()));
                    }
                    //for (HashMap<String, Object> map : hamlAbAvg) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    bean.setaList(listA);
                    //bean.setbList(listB);
                }
                break;
            case "4":
                if("1".equals(abFlg)) {
                    List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlAB(startDate, endDate, startDate2, endDate2, "2", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg2 = copyCurveMapper.selectHamlAvg(startDate, endDate, startDate, endDate, "2", lindId);

                    for (HashMap<String, String> map : hamlListAB2)
                    {
                        if (map.get("type").equals("A")) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                            countA++;
                        } else {
                            listB.add(map);
                            sumB+=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }
                    }
                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    //for (HashMap<String, Object> map : hamlAbAvg2) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    bean.setaList(listA);
                    bean.setbList(listB);
                }
                else {
                    List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlNoAB(startDate, endDate, "2", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg2 = copyCurveMapper.selectHamlNoAvg(startDate, endDate, "2", lindId);
                    for (HashMap<String, String> map : hamlListAB2) {
                        //if (A.equals(map.get("type"))) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                        //}
                        //else {
                            //listB.add(map);
                            //sumB+=sumB+Double.parseDouble(map.get("yValue"));
                        //}
                    }
                    //for (HashMap<String, Object> map : hamlAbAvg2) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    if(hamlListAB2.size()>0)
                    {
                        bean.setaAvg(Double.toString(sumA/hamlListAB2.size()));
                        //bean.setaAvg(Double.toString(sumB/hamlListAB2.size()));
                    }

                    bean.setaList(listA);
                    //bean.setbList(listB);
                }
                break;
            case "5":
                if("1".equals(abFlg)) {
                    List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlAB(startDate, endDate, startDate2, endDate2, "3", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg3 = copyCurveMapper.selectHamlAvg(startDate, endDate, startDate, endDate, "3", lindId);

                    for (HashMap<String, String> map : hamlListAB3) {
                        if (A.equals(map.get("type"))) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                            countA++;
                        } else {
                            listB.add(map);
                            sumB+=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }
                    }
                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    //for (HashMap<String, Object> map : hamlAbAvg3) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    bean.setaList(listA);
                    bean.setbList(listB);
                }else {
                    List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlNoAB(startDate, endDate, "3", lindId);
                    //List<HashMap<String, Object>> hamlAbAvg3 = copyCurveMapper.selectHamlNoAvg(startDate, endDate, "3", lindId);

                    for (HashMap<String, String> map : hamlListAB3) {
                        //if (A.equals(map.get("type"))) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));
                        //}
                        //else {
                            //listB.add(map);
                            //sumB+=sumB+Double.parseDouble(map.get("yValue"));
                        //}
                    }
                    if(hamlListAB3.size()>0)
                    {
                        bean.setaAvg(Double.toString(sumA/hamlListAB3.size()));
                        //bean.setaAvg(Double.toString(sumB/hamlListAB3.size()));
                    }
                    //for (HashMap<String, Object> map : hamlAbAvg3) {
                        //if (A.equals(map.get("type"))) {
                            //bean.setaAvg(map.get("avg").toString());
                        //} else {
                            //bean.setbAvg(map.get("avg").toString());
                        //}
                    //}
                    bean.setaList(listA);
                    //bean.setbList(listB);
                }
                break;
                default:
                    break;
        }

        }else if("2".equals(selectType)){//按照小时 //TODO

            switch (type){
                case "1":
                    if ("1".equals(abFlg)) {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthAB_H(startDate, endDate, startDate2, endDate2, lindId);

                        for (HashMap<String, String> map : listAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA += Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB += Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if (countA > 0) bean.setaAvg(Double.toString(sumA / countA));
                        if (countB > 0) bean.setbAvg(Double.toString(sumB / countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    } else {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthNoAB_H(startDate, endDate, lindId);
                        for (HashMap<String, String> map : listAB) {
                            listA.add(map);
                        }
                        if (listAB.size() > 0) {
                            bean.setaAvg(Double.toString(sumA / listAB.size()));
                        }
                        bean.setaList(listA);
                    }

                    break;
                case "2":
                    String weighNo1 ="";
                    String weighNo2 ="";
                    switch (eqNo){
                        case "1":
                            weighNo1 = "1";
                            weighNo2 = "2";
                            break;
                        case "2":
                            weighNo1 = "3";
                            weighNo2 = "4";
                            break;
                        case "3":
                            weighNo1 = "5";
                            weighNo2 = "6";
                            break;
                        case "4":
                            weighNo1 = "7";
                            weighNo2 = "8";
                            break;
                        default:
                            weighNo1 = "1";
                            weighNo2 = "2";
                            break;
                    }
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightAB(startDate, endDate, startDate2, endDate2, weighNo1, weighNo2, lindId);
                        List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightAvg(startDate, endDate, startDate, endDate, weighNo1, weighNo2, lindId);

                        for (HashMap<String, String> map : weightListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                            } else {
                                listB.add(map);
                            }
                        }

                        for (HashMap<String, Object> map : weightAbAvg) {

                            if (A.equals(map.get("type"))) {
                                bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                            } else {
                                bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                            }
                        }
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightNOAB(startDate, endDate, weighNo1, weighNo2, lindId);
                        List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightNOAvg(startDate, endDate, weighNo1, weighNo2, lindId);

                        for (HashMap<String, String> map : weightListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                            } else {
                                listB.add(map);
                            }
                        }

                        for (HashMap<String, Object> map : weightAbAvg) {

                            if (A.equals(map.get("type"))) {
                                bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                            } else {
                                bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                            }
                        }
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }
                    break;
                case "3":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlAB_H(startDate, endDate, startDate2, endDate2, "1", lindId);

                        for (HashMap<String, String> map : hamlListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlNoAB_H(startDate, endDate, "1", lindId);

                        for (HashMap<String, String> map : hamlListAB) {

                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }

                        if(hamlListAB.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB.size()));

                        }

                        bean.setaList(listA);

                    }
                    break;
                case "4":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlAB_H(startDate, endDate, startDate2, endDate2, "2", lindId);

                        for (HashMap<String, String> map : hamlListAB2)
                        {
                            if (map.get("type").equals("A")) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }
                    else {
                        List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlNoAB_H(startDate, endDate, "2", lindId);

                        for (HashMap<String, String> map : hamlListAB2) {

                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }

                        if(hamlListAB2.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB2.size()));

                        }

                        bean.setaList(listA);

                    }
                    break;
                case "5":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlAB_H(startDate, endDate, startDate2, endDate2, "3", lindId);

                        for (HashMap<String, String> map : hamlListAB3) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlNoAB_H(startDate, endDate, "3", lindId);

                        for (HashMap<String, String> map : hamlListAB3) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }
                        if(hamlListAB3.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB3.size()));

                        }

                        bean.setaList(listA);
                    }
                    break;
                default:
                    break;
            }

        }else if("3".equals(selectType)){//按照分钟 //TODO
            switch (type){
                case "1":
                    if ("1".equals(abFlg)) {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthAB_M(startDate, endDate, startDate2, endDate2, lindId);

                        for (HashMap<String, String> map : listAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA += Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB += Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if (countA > 0) bean.setaAvg(Double.toString(sumA / countA));
                        if (countB > 0) bean.setbAvg(Double.toString(sumB / countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    } else {
                        List<HashMap<String, String>> listAB = copyCurveMapper.selectWidthNoAB_M(startDate, endDate, lindId);
                        for (HashMap<String, String> map : listAB) {
                            listA.add(map);
                        }
                        if (listAB.size() > 0) {
                            bean.setaAvg(Double.toString(sumA / listAB.size()));
                        }
                        bean.setaList(listA);
                    }

                    break;
                case "2":
                    String weighNo1 ="";
                    String weighNo2 ="";
                    switch (eqNo){
                        case "1":
                            weighNo1 = "1";
                            weighNo2 = "2";
                            break;
                        case "2":
                            weighNo1 = "3";
                            weighNo2 = "4";
                            break;
                        case "3":
                            weighNo1 = "5";
                            weighNo2 = "6";
                            break;
                        case "4":
                            weighNo1 = "7";
                            weighNo2 = "8";
                            break;
                        default:
                            weighNo1 = "1";
                            weighNo2 = "2";
                            break;
                    }
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightAB(startDate, endDate, startDate2, endDate2, weighNo1, weighNo2, lindId);
                        List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightAvg(startDate, endDate, startDate, endDate, weighNo1, weighNo2, lindId);

                        for (HashMap<String, String> map : weightListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                            } else {
                                listB.add(map);
                            }
                        }

                        for (HashMap<String, Object> map : weightAbAvg) {

                            if (A.equals(map.get("type"))) {
                                bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                            } else {
                                bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                            }
                        }
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> weightListAB = copyCurveMapper.selectWeightNOAB(startDate, endDate, weighNo1, weighNo2, lindId);
                        List<HashMap<String, Object>> weightAbAvg = copyCurveMapper.selectWeightNOAvg(startDate, endDate, weighNo1, weighNo2, lindId);

                        for (HashMap<String, String> map : weightListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                            } else {
                                listB.add(map);
                            }
                        }

                        for (HashMap<String, Object> map : weightAbAvg) {

                            if (A.equals(map.get("type"))) {
                                bean.setaAvg(StringUtils.null2Length0(map.get("avgValue")));
                            } else {
                                bean.setbAvg(StringUtils.null2Length0(map.get("avgValue")));
                            }
                        }
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }
                    break;
                case "3":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlAB_M(startDate, endDate, startDate2, endDate2, "1", lindId);

                        for (HashMap<String, String> map : hamlListAB) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> hamlListAB = copyCurveMapper.selectHamlNoAB_M(startDate, endDate, "1", lindId);

                        for (HashMap<String, String> map : hamlListAB) {

                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }

                        if(hamlListAB.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB.size()));

                        }

                        bean.setaList(listA);

                    }
                    break;
                case "4":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlAB_M(startDate, endDate, startDate2, endDate2, "2", lindId);

                        for (HashMap<String, String> map : hamlListAB2)
                        {
                            if (map.get("type").equals("A")) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                        bean.setaList(listA);
                        bean.setbList(listB);
                    }
                    else {
                        List<HashMap<String, String>> hamlListAB2 = copyCurveMapper.selectHamlNoAB_M(startDate, endDate, "2", lindId);

                        for (HashMap<String, String> map : hamlListAB2) {

                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }

                        if(hamlListAB2.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB2.size()));

                        }

                        bean.setaList(listA);

                    }
                    break;
                case "5":
                    if("1".equals(abFlg)) {
                        List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlAB_M(startDate, endDate, startDate2, endDate2, "3", lindId);

                        for (HashMap<String, String> map : hamlListAB3) {
                            if (A.equals(map.get("type"))) {
                                listA.add(map);
                                sumA+=Double.parseDouble(map.get("yValue"));
                                countA++;
                            } else {
                                listB.add(map);
                                sumB+=Double.parseDouble(map.get("yValue"));
                                countB++;
                            }
                        }
                        if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                        if(countB>0)bean.setbAvg(Double.toString(sumB/countB));

                        bean.setaList(listA);
                        bean.setbList(listB);
                    }else {
                        List<HashMap<String, String>> hamlListAB3 = copyCurveMapper.selectHamlNoAB_M(startDate, endDate, "3", lindId);

                        for (HashMap<String, String> map : hamlListAB3) {
                            listA.add(map);
                            sumA+=Double.parseDouble(map.get("yValue"));

                        }
                        if(hamlListAB3.size()>0)
                        {
                            bean.setaAvg(Double.toString(sumA/hamlListAB3.size()));

                        }

                        bean.setaList(listA);
                    }
                    break;
                default:
                    break;
            }
        }
        return bean;
    }

    public CopyCurve2Bean selectCurve2(String line,String startDate, String endDate, String type,String printType,String selectType) {
        CopyCurve2Bean bean=new CopyCurve2Bean();
        List<HashMap<String,String>> listA=new ArrayList<>();
        List<HashMap<String,String>> listB=new ArrayList<>();
        List<HashMap<String,String>> listC=new ArrayList<>();
        List<HashMap<String,String>> listD=new ArrayList<>();
        double sumA=0;
        double sumB=0;
        double sumC=0;
        double sumD=0;
        int countA=0;
        int countB=0;
        int countC=0;
        int countD=0;
        if("1".equals(selectType)) {//按片
        switch (type){
            case "1":
                List<HashMap<String,String>> listData1 = copyCurveMapper.selectWidth2(line,startDate,endDate,printType);
                //List<HashMap<String,Object>> avg1 = copyCurveMapper.selectWidth2Avg(line,startDate, endDate,printType);

                for(HashMap<String,String> map:listData1){
                    if("a".equals(map.get("type"))){
                        listA.add(map);
                        sumA +=Double.parseDouble(map.get("yValue"));
                        countA++;
                    }else if("b".equals(map.get("type"))){
                        listB.add(map);
                        sumB +=Double.parseDouble(map.get("yValue"));
                        countB++;
                    }else if("c".equals(map.get("type"))){
                        listC.add(map);
                        sumC +=Double.parseDouble(map.get("yValue"));
                        countC++;
                    }else if("d".equals(map.get("type"))){
                        listD.add(map);
                        sumD +=Double.parseDouble(map.get("yValue"));
                        countD++;
                    }
                }
                if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                if(countD>0)bean.setdAvg(Double.toString(sumD/countD));
                //for(HashMap<String,Object> map:avg1){
                    //if("a".equals(map.get("type"))){
                        //bean.setaAvg(map.get("avg").toString());
                    //}else if("b".equals(map.get("type"))){
                        //bean.setbAvg(map.get("avg").toString());
                    //}else if("c".equals(map.get("type"))){
                        //bean.setcAvg(map.get("avg").toString());
                    //}else if("d".equals(map.get("type"))){
                        //bean.setdAvg(map.get("avg").toString());
                    //}
                //}
                bean.setaList(listA);
                bean.setbList(listB);
                bean.setcList(listC);
                bean.setdList(listD);
                break;
            case "2":
                List<HashMap<String,String>> listData2 = copyCurveMapper.selectWeight2(line,startDate,endDate,printType);
                List<HashMap<String,Object>> avg2 = copyCurveMapper.selectWeight2Avg(line,startDate, endDate,printType);

                for(HashMap<String,String> map:listData2){
                    if("a".equals(map.get("type"))){
                        listA.add(map);
                    }else if("b".equals(map.get("type"))){
                        listB.add(map);
                    }else if("c".equals(map.get("type"))){
                        listC.add(map);
                    }else if("d".equals(map.get("type"))){
                        listD.add(map);
                    }
                }

                for(HashMap<String,Object> map:avg2){
                    if("a".equals(map.get("type"))){
                        bean.setaAvg(map.get("avg").toString());
                    }else if("b".equals(map.get("type"))){
                        bean.setbAvg(map.get("avg").toString());
                    }else if("c".equals(map.get("type"))){
                        bean.setcAvg(map.get("avg").toString());
                    }else if("d".equals(map.get("type"))){
                        bean.setdAvg(map.get("avg").toString());
                    }
                }
                bean.setaList(listA);
                bean.setbList(listB);
                bean.setcList(listC);
                bean.setdList(listD);
                break;
            case "3":
                List<HashMap<String,String>> listData3 = copyCurveMapper.selectHaml2(line,startDate,endDate,printType);
                //List<HashMap<String,Object>> avg3 = copyCurveMapper.selectHamlAvg2(line,startDate, endDate,printType);

                for(HashMap<String,String> map:listData3){
                    if("a".equals(map.get("type"))){
                        listA.add(map);
                        sumA +=Double.parseDouble(map.get("yValue"));
                        countA++;
                    }else if("b".equals(map.get("type"))){
                        listB.add(map);
                        sumB +=Double.parseDouble(map.get("yValue"));
                        countB++;
                    }else if("c".equals(map.get("type"))){
                        listC.add(map);
                        sumC +=Double.parseDouble(map.get("yValue"));
                        countC++;
                    }else if("d".equals(map.get("type"))){
                        listD.add(map);
                        sumD +=Double.parseDouble(map.get("yValue"));
                        countD++;
                    }
                }
                //for(HashMap<String,Object> map:avg3){
                    //if("a".equals(map.get("type"))){
                        //bean.setaAvg(map.get("avg").toString());
                    //}else if("b".equals(map.get("type"))){
                        //bean.setbAvg(map.get("avg").toString());
                    //}else if("c".equals(map.get("type"))){
                        //bean.setcAvg(map.get("avg").toString());
                    //}else if("d".equals(map.get("type"))){
                        //bean.setdAvg(map.get("avg").toString());
                    //}
                //}
                if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                if(countD>0)bean.setdAvg(Double.toString(sumD/countD));
                bean.setaList(listA);
                bean.setbList(listB);
                bean.setcList(listC);
                bean.setdList(listD);
                break;
                default:break;
        }
        }else if("2".equals(selectType)){//按照小时 //TODO

            switch (type){
                case "1":
                    List<HashMap<String,String>> listData1 = copyCurveMapper.selectWidth2_H(line,startDate,endDate,printType);

                    for(HashMap<String,String> map:listData1){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                            sumA +=Double.parseDouble(map.get("yValue"));
                            countA++;
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                            sumB +=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                            sumC +=Double.parseDouble(map.get("yValue"));
                            countC++;
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                            sumD +=Double.parseDouble(map.get("yValue"));
                            countD++;
                        }
                    }
                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                    if(countD>0)bean.setdAvg(Double.toString(sumD/countD));

                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                case "2":
                    List<HashMap<String,String>> listData2 = copyCurveMapper.selectWeight2(line,startDate,endDate,printType);
                    List<HashMap<String,Object>> avg2 = copyCurveMapper.selectWeight2Avg(line,startDate, endDate,printType);

                    for(HashMap<String,String> map:listData2){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                        }
                    }

                    for(HashMap<String,Object> map:avg2){
                        if("a".equals(map.get("type"))){
                            bean.setaAvg(map.get("avg").toString());
                        }else if("b".equals(map.get("type"))){
                            bean.setbAvg(map.get("avg").toString());
                        }else if("c".equals(map.get("type"))){
                            bean.setcAvg(map.get("avg").toString());
                        }else if("d".equals(map.get("type"))){
                            bean.setdAvg(map.get("avg").toString());
                        }
                    }
                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                case "3":
                    List<HashMap<String,String>> listData3 = copyCurveMapper.selectHaml2_H(line,startDate,endDate,printType);

                    for(HashMap<String,String> map:listData3){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                            sumA +=Double.parseDouble(map.get("yValue"));
                            countA++;
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                            sumB +=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                            sumC +=Double.parseDouble(map.get("yValue"));
                            countC++;
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                            sumD +=Double.parseDouble(map.get("yValue"));
                            countD++;
                        }
                    }

                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                    if(countD>0)bean.setdAvg(Double.toString(sumD/countD));
                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                default:break;
            }

        }else if("3".equals(selectType)){//按照秒 //TODO

            switch (type){
                case "1":
                    List<HashMap<String,String>> listData1 = copyCurveMapper.selectWidth2_M(line,startDate,endDate,printType);

                    for(HashMap<String,String> map:listData1){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                            sumA +=Double.parseDouble(map.get("yValue"));
                            countA++;
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                            sumB +=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                            sumC +=Double.parseDouble(map.get("yValue"));
                            countC++;
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                            sumD +=Double.parseDouble(map.get("yValue"));
                            countD++;
                        }
                    }
                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                    if(countD>0)bean.setdAvg(Double.toString(sumD/countD));

                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                case "2":
                    List<HashMap<String,String>> listData2 = copyCurveMapper.selectWeight2(line,startDate,endDate,printType);
                    List<HashMap<String,Object>> avg2 = copyCurveMapper.selectWeight2Avg(line,startDate, endDate,printType);

                    for(HashMap<String,String> map:listData2){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                        }
                    }

                    for(HashMap<String,Object> map:avg2){
                        if("a".equals(map.get("type"))){
                            bean.setaAvg(map.get("avg").toString());
                        }else if("b".equals(map.get("type"))){
                            bean.setbAvg(map.get("avg").toString());
                        }else if("c".equals(map.get("type"))){
                            bean.setcAvg(map.get("avg").toString());
                        }else if("d".equals(map.get("type"))){
                            bean.setdAvg(map.get("avg").toString());
                        }
                    }
                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                case "3":
                    List<HashMap<String,String>> listData3 = copyCurveMapper.selectHaml2_M(line,startDate,endDate,printType);

                    for(HashMap<String,String> map:listData3){
                        if("a".equals(map.get("type"))){
                            listA.add(map);
                            sumA +=Double.parseDouble(map.get("yValue"));
                            countA++;
                        }else if("b".equals(map.get("type"))){
                            listB.add(map);
                            sumB +=Double.parseDouble(map.get("yValue"));
                            countB++;
                        }else if("c".equals(map.get("type"))){
                            listC.add(map);
                            sumC +=Double.parseDouble(map.get("yValue"));
                            countC++;
                        }else if("d".equals(map.get("type"))){
                            listD.add(map);
                            sumD +=Double.parseDouble(map.get("yValue"));
                            countD++;
                        }
                    }

                    if(countA>0)bean.setaAvg(Double.toString(sumA/countA));
                    if(countB>0)bean.setbAvg(Double.toString(sumB/countB));
                    if(countC>0)bean.setcAvg(Double.toString(sumC/countC));
                    if(countD>0)bean.setdAvg(Double.toString(sumD/countD));
                    bean.setaList(listA);
                    bean.setbList(listB);
                    bean.setcList(listC);
                    bean.setdList(listD);
                    break;
                default:break;
            }
        }

        return bean;
    }


}
